package job

// 单词反转 // "ab bc cd" => "cd bc ab"
func revert(s string) string {
	result := ""
	beg := 0
	length := len(s)
	i := 0
	for ; i < length && beg <= length; i++ {
		if s[i] == ' ' && i >= beg {
			if i == beg { // 处理连续空格情况
				result = " " + result
			} else { // 处理常规单词
				result = " " + s[beg:i] + result
			}
			beg = i + 1
		}
	}
	if beg < i && beg < length { // 处理最后一个单测
		result = s[beg:] + result
	}
	return result
}
